package thread;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class TestThread02 extends Thread{
    private String url;
    private String fileName;

    public TestThread02(String url,String fileName){
        this.url = url;
        this.fileName = fileName;
    }

    @Override
    public void run() {
        //线程体
        WebDownloader wl = new WebDownloader();
        wl.downloader(this.url,this.fileName);
        System.out.println("download" + this.fileName);
    }

    public static void main(String[] args) {
        TestThread02 t1 = new TestThread02("https://portal-minio.nwpu.edu.cn/service/%E5%AD%A6%E7%94%9F%E7%AE%A1%E7%90%86-1632993348940.png","1.png");
        TestThread02 t2 = new TestThread02("https://portal-minio.nwpu.edu.cn/service/%E5%AD%A6%E7%94%9F%E7%AE%A1%E7%90%86-1632993348940.png","2.png");
        TestThread02 t3 = new TestThread02("https://portal-minio.nwpu.edu.cn/service/%E5%AD%A6%E7%94%9F%E7%AE%A1%E7%90%86-1632993348940.png","3.png");

        t1.start();
        t2.start();
        t3.start();
    }
}

class WebDownloader{
    public void downloader(String url,String fileName){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(fileName));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("IO异常，downloader出现问题");
        }
    }
}